Ext.namespace("Hroze");
/**
 * @description 数据展示
 * @class Hroze.View 数据展示类
 * @extends Ext.util.Observable
 */
Hroze.View = Ext.extend(Ext.util.Observable, {
			/**
			 * 
			 * @type {Hroze.PageBar} 翻页工具条
			 */
			pageBar : "",
			emptyMsg : "没有找到任何数据！",
			constructor : function(element, config) {
				Ext.apply(this, config);
				Hroze.View.superclass.constructor.call(this);
				this.addEvents('onselect', 'onload', 'onrender');
				this.el = Ext.get(element);
				this.init();
			},
			init : function() {
				// 注册事件
				if (this.pageBar) {
					this.pageBar.on('onload', this.onload, this);
				}
			},
			load : function(cfg) {
				Ext.applyIf(this, cfg);
				// 使用工具条的装载
				if (this.pageBar) {
					this.pageBar.load({
								url : this.url,
								params : this.params
							});
				} else {
					Hroze.util.request({
								url : this.url,
								params : this.params,
								success : this.onload,
								scope : this
							});
				}
			},
			onload : function(text, result, isJSON) {
				if (isJSON) {
					this.data = result;
					this.fireEvent("onload", text, result, isJSON, this);
					this.render();
				}
			},
			render : function() {
				if (this.cleaner) {
					this.cleaner();
				}
				if (this.data.size > 0) {
					if (this.el) {
						this.el.update("");
					}
					if (this.renderer) {
						this.renderer(this.data);
					}
				} else {
					if (this.el) {
						this.el.update(this.emptyMsg);
					} else {
						alert("没有符合条件的数据！");
					}
				}
				this.onrender();

			},
			onrender : function() {
				this.fireEvent("onrender", this.data, this);
			}
		});